package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// PublishDevice 投放设备表
type PublishDevice struct {
	ID        string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	GroupID   string `json:"group_id" gorm:"column:group_id;type:int;size:64;not null;default:0;comment:分组id"`
	RobotName string `json:"robot_name" gorm:"column:robot_name;type:string;size:50;not null;default:'';comment:设备名称"`
	CreatedAt int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;not null;default:0;index:created_at;comment:创建时间"`
}

// TableName 表名
func (PublishDevice) TableName() string {
	return "publish_device"
}

// BeforeCreate 自增id
func (l *PublishDevice) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID == "" {
		// id为空时，自动添加id
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		l.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &PublishDevice{})
}
